<template>
    <div class="bigbox">
        <Loading :show="show"></Loading>
        <div class="detail">
            <div class="search">
                <a-input v-model:value="keyWord" placeholder="搜索" allowClear/>
            </div>
            <div class="item everyItem" v-for="(item, i) in allDataInfo" @click="viewDetail(item, i)"
                :class="i == indexOf ? 'active' : ''" v-show="item.name.includes(keyWord)">
                <h2>{{ item.name }}</h2>
            </div>
        </div>
        <ul class="info">
            <li v-for="(item, i) in detailInfo" v-slide-in="{ distance: 30, time: 500 }">
                <h1>
                    <a :href="item.href" target="_blank">
                        <span class="serialNumber" :style="{ 'opacity': computerBackColor(i) }">{{ i + 1
                            }}</span>
                        {{ item.title }}
                    </a>
                    <span v-show="item.hot" class="hot">实时：{{ item.hot }}</span>
                </h1>
            </li>
        </ul>
    </div>
</template>

<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { allNews2 } from '@/api/index'
const keyWord = ref('')
const show = ref(false)
const allDataInfo: any = ref([])
const detailInfo: any = ref()
const indexOf = ref(0)
const getData = async () => {
    try {
        const result = await allNews2()
        for (const key in result.result) {
            const obj = {
                name: key,
                data: result.result[key]
            }
            allDataInfo.value.push(obj)
        }
        detailInfo.value = allDataInfo.value[0].data
        show.value = true

    } catch (error) {
        show.value = true
    }
}
const viewDetail = (el: any, index: number) => {
    detailInfo.value = []
    setTimeout(() => {
        detailInfo.value = el.data
    }, 200);
    indexOf.value = index
}
const computerBackColor = (i: number): string => {
    let transparent: any = (30 - i * 5) / 30
    if (transparent < 0.3) transparent = 0.3
    return transparent
}


onMounted(async () => {
    getData()
})
</script>

<style lang="scss" scoped>
.bigbox {
    height: 100%;
    width: 100%;
    position: relative;
    display: grid;
    grid-template-columns: 200px 1fr;

    .detail {
        position: relative;
        display: grid;
        grid-template-columns: 1fr;
        gap: 10px;
        padding: 10px;
        background-color: var(--backColor);
        height: fit-content;
        max-height: 100%;
        overflow-y: auto;
        @include scroll-bar(white, rgba(135, 207, 235, 0.529));

        .search {
            position: sticky;
            top: 0;
        }

        .item {
            border-radius: 10px;
            text-align: center;
            cursor: pointer;
            padding: 10px;
            box-shadow:
                2px 3px 10px rgba(128, 128, 128, 0.174),
                -1px 2px 5px rgb(226, 216, 216);

            &:hover {
                color: white;
                background-color: var(--themeColor);
            }
        }

        .active {
            color: white;
            background-color: var(--themeColor);
        }

        .border {
            --h: 10px;
            transition: all var(--s);
            padding: 10px;
            border-radius: 10px;
            width: var(--w);
            height: var(--h);
            border: 3px solid var(--themeColor);
            position: absolute;
            top: var(--t);
            left: 50%;
            transform: translateX(-50%);
        }
    }

    .info {
        height: fit-content;
        max-height: 100%;
        overflow-y: auto;
        @include scroll-bar();
        display: grid;
        grid-template-columns: 1fr 1fr;
        width: 100%;
        list-style-type: none;
        gap: 10px;
        padding: 10px;

        li {
            padding: 10px;
            box-shadow:
                2px 3px 5px rgba(128, 128, 128, 0.1),
                -1px 2px 5px rgb(226, 216, 216),
                -1px -2px 5px rgba(128, 128, 128, 0.1);

            h1 {
                display: grid;
                grid-template-columns: 1fr 150px;

                a {
                    color: var(--backColorText);

                    .serialNumber {
                        width: 20px;
                        background-color: var(--themeColor);
                        height: 20px;
                        line-height: 20px;
                        border-radius: 50%;
                        text-align: center;
                        font-size: 15px;
                        color: white;
                        display: inline-block;
                    }

                    &:hover {
                        color: $primary;
                    }
                }

                .hot {
                    padding-left: 20px;
                }
            }
        }
    }
}
</style>